//
//  CashDepositVC.m
//  NtoccShipper
//
//  Created by mac on 2020/2/17.
//  Copyright © 2020 zhuchongjin. All rights reserved.
//

#import "CashDepositVC.h"
#import "RollOutToBalanceVC.h"
#import "ShiftToCashDepVC.h"

@interface CashDepositVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIImageView *imgVBG;
@property (nonatomic,copy) NSDictionary *dicUserInfo;
@property (strong, nonatomic) CJTableView *tableView;
@property (nonatomic,copy)NSArray *arrImgs;
@property (nonatomic,copy)NSArray *arrTitles;
@property (weak, nonatomic) IBOutlet UILabel *labEnsureFee;
@property (weak, nonatomic) IBOutlet UILabel *labEnsureFeeAmount;
@end

@implementation CashDepositVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:CJLString(@"保证金")];
    [self setBackLeftButton:@""];
    [self.view addSubview:self.tableView];
    self.imgVBG.backgroundColor = [UIColor cjMainColor];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setWhiterColorAppNavigationBarStyle];
    [self getUSerInfo];
}

- (void)getUSerInfo{
    @weakify(self);
    [CJNetWork getPartyUserCenterInfoSuccess:^(id responseObject) {
        
        @strongify(self);
        NSDictionary *dic = (NSDictionary *)responseObject;
        DLog(@"+++++ %@",dic);
        self.dicUserInfo = dic;
        self.labEnsureFee.text = CJStringWithFormat(@"%@",@([[CJControl getThreeUnaryValueStr:dic[@"ensureFee"]] floatValue]).cj_money_description);
        self.labEnsureFeeAmount.text = CJStringWithFormat(@"%@",@([[CJControl getThreeUnaryValueStr:dic[@"ensureFeeAmount"]] floatValue]).cj_money_description);
    }];
}

#pragma mark----tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    //return self.titles.count+ 1;
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2 ;//self.arrTitles.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *MeViewCellId = @"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MeViewCellId];
    if (cell ==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MeViewCellId];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.textLabel.font = [UIFont cjTitleFont15];
        cell.textLabel.textColor = [UIColor cjMainTextColor];
    }
    
    cell.imageView.image = [UIImage imageNamed:self.arrImgs[indexPath.row]];
    CGSize itemSize = CGSizeMake(20, 20);
    UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
    [cell.imageView.image drawInRect:imageRect];
    cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    cell.textLabel.text = self.arrTitles[indexPath.row];
    cell.separatorInset = UIEdgeInsetsMake(0.3f, 50.0f, 0.0f,0.0f);
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    UIViewController *vc;
    if (indexPath.row == 0) {
        ShiftToCashDepVC * vc = [ShiftToCashDepVC new];
        vc.strEnsureFeeAmount = CJStringWithFormat(@"%@",self.dicUserInfo[@"balance"]);
        [self pushVc:vc];
    }else if (indexPath.row == 1){
       RollOutToBalanceVC *vc = [RollOutToBalanceVC new];
//        vc = [CashDepositVC new];
        vc.strEnsureFee = CJStringWithFormat(@"%@",@([[CJControl getThreeUnaryValueStr:self.dicUserInfo[@"ensureFeeAmount"]] floatValue]).cj_money_description);
        [self pushVc:vc];
    }
//    [self pushVc:vc];
}

- (CJTableView *)tableView{
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, self.imgVBG.bottom +10, SCREEN_WIDTH, SCREEN_HEIGHT-kTopHeight  - self.imgVBG.height  - 10),UITableViewStylePlain)
        .tbDelegate(self)
        .tbDataSource(self)
        .tbSetOther(YES)
        .tbEstimatedRowHeight(YES)
        ;
    }
    
    return _tableView;
}

- (NSArray *)arrTitles{
    
    if(!_arrTitles){
        _arrTitles = @[@"转入",@"转出"];
    }
    return _arrTitles;
}

- (NSArray *)arrImgs{
    if(!_arrImgs){
        _arrImgs = @[@"zcj_icon_record",@"zcj_icon_feeInfo"];
    }
    return _arrImgs;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
